package com.aaa.base.controller;


import com.aaa.base.service.WarehouseService;
import com.aaa.entity.base.Warehouse;
import com.aaa.vo.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author aaa
 * @since 2020-11-23
 */
@RestController
@RequestMapping("/base/warehouse")
public class WarehouseController {
    @Autowired
    private WarehouseService warehouseService;
    @PostMapping("searchWareHouse")
    @ApiOperation(value = "根据条件分页查询仓库")
    public R searchWareHouse(){
        List<Warehouse> warehouses = warehouseService.list();
        return R.ok().data("warehouses",warehouses);
    }
    @PostMapping("addOrupWarehouse")
    @ApiOperation(value = "新增或者更新仓库")
    public R addOrupWarehouse(@RequestBody Warehouse warehouse){
        boolean b = warehouseService.saveOrUpdate(warehouse);
        return R.ok().message("操作成功").code(200);
    }
    @DeleteMapping("deleteWarehouse/{deptId}")
    @ApiOperation(value = "根据id删除仓库")
    public R deleteWarehouse(@PathVariable Long deptId){
        boolean b = warehouseService.removeById(deptId);
        if (b) {
            return R.ok().success(b).message("删除成功");
        }
        else {
            return R.error().message("删除失败");
        }
    }
    @PostMapping("searchWare")
    public List<Warehouse> searchWare(){
        return warehouseService.list();
    }
    @PostMapping("selectWareById")
    public Warehouse selectWareById(@RequestParam Long warehouseid){
        return warehouseService.getById(warehouseid);
    }

}

